/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.stuffrepos.bricknetcenter.util;

import java.util.regex.Matcher;
import net.stuffrepos.bricknetcenter.http.HttpRequest;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public class Debug {

    public static String matchPattern(Matcher matcher) {
        StringBuilder b = new StringBuilder();
        b.append("Pattern: \"").append(matcher.pattern().pattern()).append("\"\n");
        b.append("Groups: ").append(matcher.groupCount()).append("\n");

        for (int i = 0; i < matcher.groupCount(); i++) {
            b.append(i).append(": \"").append(matcher.group()).append("\"\n");
        }

        return b.toString();
    }

    public static String requestToString(HttpRequest request) {
        StringBuilder b = new StringBuilder();
        b.append(request.getUrl().toString());
        if (request.getPostParameters().length > 0) {
            b.append(" (");
            for (HttpRequest.PostParameter pp : request.getPostParameters()) {
                b.append(pp.getName()).append("=").append(pp.getValue()).append(",");
            }
            b.append(")");
        }

        return b.toString();

    }
}
